<script setup lang="ts">
import { ref } from 'vue'
import { useRouter, useRoute } from 'vue-router';
import { blestore } from '../../store/ble';
// const { contextBridge, ipcRenderer } = require("electron");
// const ipcRenderer = useIpcRenderer();
const bleStore = blestore()
const setPagetitle = ref("蓝牙")
const centerDialogVisible = ref<boolean>(false)
const router = useRouter()
const route = useRoute()
const closeWindow = () => {
    console.log("Closing window")
    window.electronAPI.closeElectronWindow();
    // ipcRenderer.send("close-window", "close")
}
const minWindow = () => {
    console.log("min window")
    window.electronAPI.hideElectronWindow();
}
const moveWidow = (e: Event) => {
    console.log(e);
}
const disconnectBLE = () => {
    centerDialogVisible.value = true

}

const closeDialog = () => {
    centerDialogVisible.value = false
}
// defineProps<{ titleHead: string }>()
const submitConfirm = () => {
    centerDialogVisible.value = false
    console.log("disconnect")
    bleStore.changeBLEState(false)
    let obj = bleStore.BLEData
    obj.text = ""
    obj.value = ""
    bleStore.putBleData(obj)
    console.log(bleStore.isConnectBLE)
    console.log(bleStore.BLEData)
    console.log(route)
    console.log(route.path)
    router.push({
         path: route.path,
         query:{date:(new Date()).getTime()}
     })
    // router.go(-1)


}
</script>
<template>
    <div class="head">
        <div class="no-select titlehead">
            <el-icon>
                <Orange />
            </el-icon>
        </div>
        <div class="ble-title" v-if="bleStore.isConnectBLE">
            <el-button type="primary" :disabled="false" @click="disconnectBLE" class="ble-title-button">
                <el-icon>
                    <SwitchButton />
                </el-icon>
                {{ bleStore.BLEData.text }}
            </el-button>
        </div>
        <div class="right-menu ">
            <el-button size="small" type="primary" @click="minWindow">
                <el-icon>
                    <Minus />
                </el-icon>
            </el-button>
            <el-button size="small" type="primary" @click="closeWindow">
                <el-icon>
                    <Close />
                </el-icon>
            </el-button>
        </div>
    </div>

    <el-dialog v-model="centerDialogVisible" :title="setPagetitle" width="30%" align-center @close="closeDialog">
        <span>确认断开蓝牙？</span>
        <template #footer>
            <span class="dialog-footer">
                <el-button @click="closeDialog">取消</el-button>
                <el-button type="primary" @click="submitConfirm">
                    确认
                </el-button>
            </span>
        </template>
    </el-dialog>
</template>
<style lang="scss" scoped>
.head {
    z-index: 10000;
    width: 100%;
    position: fixed;
    left: 0px;
    display: flex;
    margin: 0;
    padding: 0 5px;
    overflow: hidden;
    background: #409EFF;
    -webkit-app-region: drag;

    .titlehead {
        color: #fafafa;
        text-align: left;
        font-size: 1.2rem;
        line-height: 2.3rem;

    }

    .ble-title {
        color: #fafafa;
        width: 100%;
        display: flex;
        justify-content: center;
        justify-items: center;
        text-align: center;

        .ble-title-button {
            -webkit-app-region: no-drag;
        }
    }

    .right-menu {
        position: absolute;
        top: 5px;
        right: 20px;
        -webkit-app-region: no-drag;

    }
}
</style>
